package com.zzg.cloud.healthupload;

import com.netflix.appinfo.HealthCheckHandler;
import com.netflix.appinfo.InstanceInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

/**
 * 自定义服务状态收集器
 */
@Component
@Slf4j
public class MyHealthCheckHandler implements HealthCheckHandler {
    @Resource
    private MyHealthIndicator myHealthIndicator;
    
    public InstanceInfo.InstanceStatus getStatus(InstanceInfo.InstanceStatus currentStatus){
        Status status = myHealthIndicator.health().getStatus();
        if(Status.UP.equals(status)){
            log.info("检测结果：当前服务状态正常");
            return InstanceInfo.InstanceStatus.UP;
        }else{
            log.info("检测结果：当前服务状态异常");
            return InstanceInfo.InstanceStatus.DOWN;
        }
    }
    
}
